package com.ewzj.bigdata.mvp.ui.holder

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout

import com.bigkoo.convenientbanner.holder.Holder
import com.bumptech.glide.Glide
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.mvp.model.rspbean.AdBean

/**
 * author:zhangjing
 * 作用:
 * return:
 */

class AdHolderView : Holder<AdBean.ListEntity.ImagesEntity> {
    private var view: ImageView? = null

    var updateListener: UpdateListener? = null
    override fun createView(context: Context): View? {
        view = ImageView(context)
        view!!.scaleType = ImageView.ScaleType.CENTER_CROP
        val layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        view!!.layoutParams = layoutParams
        return view
    }

    override fun UpdateUI(context: Context, position: Int, data: AdBean.ListEntity.ImagesEntity?) {
        var resId = Apputils.Utils.getImgUrl(data!!.img_path)
        if (TextUtils.isEmpty(data!!.go_url)){
            Glide.with(context).load(data.imgdrawable).into(view!!)
        }else{
            Glide.with(context).load(resId).into(view!!)
        }
        if (updateListener != null) {
            updateListener!!.update(data)
        }
    }

    interface UpdateListener {
        fun update(i: AdBean.ListEntity.ImagesEntity)
    }

}
